import React from 'react'
import io from 'socket.io-client'
import { List, InputItem } from 'antd-mobile'

const socket = io('ws://192.168.31.124:3030')

socket.on('recvmsg', data => {
  console.log(data)
})
class Chat extends React.Component{
  constructor(props) {
    super(props)
    this.state = { 
      text: ''
    }
  }
  handleSubmit = () => {
    const { text } = this.state
    console.log(text)
    socket.emit('sendmsg', { text })
    this.setState({
      state: ''
    })
  }
  render() {
    return (
      <div className="stick-footer"> 
        <List>
          <InputItem
            placeholder="请输入"
            value={ this.state.text }
            onChange={ v => {
              this.setState({
                text: v
              }) 
            }}
            extra={ <span onClick={ this.handleSubmit }>发送</span> }
          />
        </List>
      </div>
    )
  }
}

export default Chat